package com.simulation.ctrl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @author zhangxn
 * @date 2022/12/20  20:52
 */
@Slf4j
@RestController
@RequestMapping("/file")
public class UploadFileController {

    @RequestMapping("/upload")
    public String upload(MultipartFile file)  {
        //实现文件上传
        String dir="/home/ubuntu/qemu-stm32/build/arm-softmmu/";//建议这里写resources目录的绝对路径
        File path = new File(dir+"/upload/");
        if(!path.exists()){//如果当前目录不存在
            path.mkdir();
        }
        File fileSave =new File(dir+"/upload/"+ file.getOriginalFilename());
        try {
            file.transferTo(fileSave);//将此图像保存到file本地
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "文件上传成功";
    }

}
